#include <fstream>
#include <iostream>
#include <range/v3/action/sort.hpp>
#include <range/v3/all.hpp>
#include <range/v3/view/take.hpp>
#include <string>
#include <vector>

using namespace ranges;
using namespace ranges::views;

std::vector<std::string> words(const std::string& file_path)
{
    std::ifstream in(file_path);
    if (!in)
        return {};
    std::istream_iterator<std::string> start(in), end;
    return ranges::accumulate(
        start, end,
        std::vector<std::string> {},
        [](std::vector<std::string> acc, std::string word) {
            if (!word.empty())
                acc.push_back(std::move(word));
            return acc;
        });
}

int main()
{
    std::string file_path = "/data/workspace/Func_progra/src/fp_7_2.cc";
    auto datas = words(file_path);
    datas |= actions::sort;
    for (auto& data : datas) {
        std::cout << data << std::endl;
    }
    std::cout << "--------------------" << std::endl;
    auto thn = datas | views::take(3);
    for (auto& data : thn) {
        std::cout << data << std::endl;
    }
}